using System.Windows;
using System.Windows.Markup;
using Common;

namespace MainView.Windows
{
	public partial class ExperimentEncryptWindow : Window, IComponentConnector
	{
		public string InputPassword { get; set; }

		public ExperimentEncryptWindow()
		{
			InitializeComponent();
			checkEdit.IsChecked = true;
		}

		private void btnOK_Click(object sender, RoutedEventArgs e)
		{
			if (checkEdit.IsChecked == true)
			{
				if (passwordBoxEdit.Password.Length < 6)
				{
					MessageBox.Show(string.Format(Utility.GetMessage("msg_password_length_less"), 6));
					passwordBoxEdit.SelectAll();
					passwordBoxEdit.Focus();
					return;
				}
				if (!passwordBoxEdit.Password.Equals(passwordBoxEditRepeat.Password))
				{
					MessageBox.Show(Utility.GetMessage("msg_password_not_same"));
					passwordBoxEditRepeat.SelectAll();
					passwordBoxEditRepeat.Focus();
					return;
				}
				InputPassword = passwordBoxEditRepeat.Password;
			}
			else
			{
				InputPassword = string.Empty;
			}
			base.DialogResult = true;
		}

		private void checkEdit_Checked(object sender, RoutedEventArgs e)
		{
			passwordBoxEdit.IsEnabled = true;
			passwordBoxEditRepeat.IsEnabled = true;
			passwordBoxEdit.Focus();
		}

		private void checkEdit_Unchecked(object sender, RoutedEventArgs e)
		{
			passwordBoxEdit.Password = "";
			passwordBoxEditRepeat.Password = "";
			passwordBoxEdit.IsEnabled = false;
			passwordBoxEditRepeat.IsEnabled = false;
		}
	}
}
